<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/file-upload.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GroupSummary.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript" src="../../scripts/selectZip.js">
        </script>
        <script type="text/javascript">
            var idValue = getPrarmeterValue(window.location, 'id');
            var startPage = getPrarmeterValue(window.location, 'startPage');
            
            var piMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.productidentification');
            var tlMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.producttimeline');
			var referenceMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.reference');
			var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
			
			var ctYesnoXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtYesno');
            var ctYesnoStore = new Ext.data.Store({
                reader: new Ext.data.XmlReader({
                    record: 'item',
                    id: 'code',
                    totalRecords: 'itemTotal'
                }, [ 
                'code', 'description']),
				data: ctYesnoXmlLoader.getXml()
            });
			
			var isEffectiveCombo = new Ext.form.ComboBox({
				fieldLabel: tlMessage.get('ui.producttimeline.iseffective'),
				id: 'isEffective',
				name: 'isEffective',
				allowBlank: false,
                blankText: message.get('message.edit.noblank'),
				editable: false,
			    store: ctYesnoStore,
				valueField: 'code',
			    displayField:'description',
			    triggerAction: 'all',
			    emptyText: message.get('message.combo.pleaseselect'),
			    selectOnFocus:true,
				mode: 'local'
			});
			
			var isFinishedCombo = new Ext.form.ComboBox({
				fieldLabel: tlMessage.get('ui.producttimeline.isfinished'),
				id: 'isFinished',
				name: 'isFinished',
				allowBlank: false,
                blankText: message.get('message.edit.noblank'),
				editable: false,
			    store: ctYesnoStore,
				valueField: 'code',
			    displayField:'description',
			    triggerAction: 'all',
			    emptyText: message.get('message.combo.pleaseselect'),
			    selectOnFocus:true,
				mode: 'local'
			});
			
            var timeLineForm
            var timeLineStore;
            var timeLineGrid;
            
            Ext.onReady(function(){
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';
                
                var piXMLReader = new Ext.data.XmlReader({
                    record: 'item'
                }, [{
                    name: 'id',
                    mapping: 'id'
                }, {
                    name: 'ctProductFamily',
                    mapping: 'ctProductFamily'
                }, {
                    name: 'ctMachineType',
                    mapping: 'ctMachineType'
                }, {
                    name: 'type',
                    mapping: 'type'
                }, {
                    name: 'orderNumber',
                    mapping: 'orderNumber'
                }, {
                    name: 'yarnNumber',
                    mapping: 'yarnNumber'
                }, {
                    name: 'ctDesignType',
                    mapping: 'ctDesignType'
                }, {
                    name: 'style',
                    mapping: 'style'
                }, {
                    name: 'customerLinkman',
                    mapping: 'customerLinkman'
                }, {
                    name: 'model',
                    mapping: 'model'
                }, {
                    name: 'ctSeasonNumber',
                    mapping: 'ctSeasonNumber'
                }, {
                    name: 'reference',
                    mapping: 'reference'
                }, {
                    name: 'createDate',
                    mapping: 'createDate'
                }, {
                    name: 'ctVersion',
                    mapping: 'ctVersion'
                }, {
                    name: 'patronageNumer',
                    mapping: 'patronageNumer'
                }, {
                    name: 'front',
                    mapping: 'front'
                }, {
                    name: 'back',
                    mapping: 'back'
                }, {
                    name: 'sleeves',
                    mapping: 'sleeves'
                }, {
                    name: 'bottomThrum',
                    mapping: 'bottomThrum'
                }, {
                    name: 'sleevesThrum',
                    mapping: 'sleevesThrum'
                }, {
                    name: 'necklineThrum',
                    mapping: 'necklineThrum'
                }, {
                    name: 'needle',
                    mapping: 'needle'
                }, {
                    name: 'weight',
                    mapping: 'weight'
                }, {
                    name: 'comment',
                    mapping: 'comment'
                }, {
                    name: 'customerID',
                    mapping: 'customerID'
                }, {
                    name: 'photoName',
                    mapping: 'photoName'
                }, {
                    name: 'chartName',
                    mapping: 'chartName'
                }, {
                    name: 'biMeasureSpecificationId',
                    mapping: 'biMeasureSpecificationId'
                }, {
                    name: 'biMeasureSpecificationName',
                    mapping: 'biMeasureSpecificationName'
                }, {
                    name: 'yarnName',
                    mapping: 'yarnName'
                }, {
                    name: 'frontPhotoName',
                    mapping: 'frontPhotoName'
                }, {
                    name: 'backPhotoName',
                    mapping: 'backPhotoName'
                }, {
                    name: 'photoName',
                    mapping: 'photoName'
                }, {
                    name: 'chartName',
                    mapping: 'chartName'
                }, {
                    name: 'ctCollarType',
                    mapping: 'ctCollarType'
                }, {
                    name: 'customerName',
                    mapping: 'customerName'
                }, {
                    name: 'customerDepartment',
                    mapping: 'customerDepartment'
                }]);
                
                var piXmlLoader = new xmlLoader('../../servlet/ProductIdentificationServlet?action=11&id=' + idValue);
                
                var piRecord = piXMLReader.readRecords(piXmlLoader.getXml()).records[0];
                
                var itemTplMarkup = ['<table cellspacing="0" id="the-table" style="width: 100%;"><tbody>',
										 '<tr><td style="background:#eeeeee; width: 15%;">',
										 message.get('message.list.id'), '</td><td>{id}</td>', 
										 '<td style="background:#eeeeee;width: 15%;">', 
										 piMessage.get('ui.productidentification.style'), 
										 '</td><td>{style}</td><td style="background:#eeeeee;">', 
										 piMessage.get('ui.productidentification.seasonnumber'), 
										 '</td><td>{ctSeasonNumber}</td>', '<td style="background:#eeeeee;">', 
										 referenceMessage.get('ui.reference.reference'), 
										 '</td><td>{reference}</td></tr>', 
										 
										 
										 '<tr><td style="background:#eeeeee;">', 
										 message.get('message.edit.productfamily'), 
										 '</td><td>{ctProductFamily}</td><td style="background:#eeeeee;">', 
										 piMessage.get('ui.productidentification.patronagenumer'), 
										 '</td><td>{patronageNumer}</td><td style="background:#eeeeee;">', 
										 piMessage.get('ui.productidentification.chartversion'), 
										 '</td><td>{ctVersion}</td><td style="background:#eeeeee;">', 
										 piMessage.get('ui.productidentification.model'), 
										 '</td><td>{model}</td></tr>',
										 '<tr><td style="background:#eeeeee;">', 
										 referenceMessage.get('ui.reference.weight'), 
										 '</td><td>{weight}</td><td style="background:#eeeeee;">', 
										 message.get('message.edit.collar'), 
										 '</td><td>{ctCollarType}</td><td style="background:#eeeeee;">', 
										 fcMessage.get('ui.francecustomer.name'), 
										 '</td><td>{customerName}</td><td style="background:#eeeeee;">', 
										 fcMessage.get('ui.francecustomer.department'), 
										 '</td><td>{customerDepartment}</td></tr>',
										 
										 '<tr><td colspan="8">',
										 //'<img width="120" src="../../_temp/{frontPhotoName}"/>&nbsp;&nbsp;&nbsp;&nbsp;',
										 //'<img width="120" src="../../_temp/{backPhotoName}"/>&nbsp;&nbsp;&nbsp;&nbsp;',
										 '<img width="120" src="../../_temp/{chartName}"/>&nbsp;&nbsp;&nbsp;&nbsp;',
										 '<img width="120" src="../../_temp/{photoName}"/>',
										 '</td></tr>',
										 '</tbody></table>'];
                var itemTpl = new Ext.Template(itemTplMarkup);
                itemTpl.append('productIdentification', piRecord.data);
                
                timeLineForm = new Ext.FormPanel({
                    labelAlign: 'left',
                    url: '../../servlet/ProductTimeLineServlet?action=1',
                    frame: true,
                    title: tlMessage.get('ui.producttimeline.edittitle'),
                    bodyStyle: 'padding:5px 5px 5px 5px;margin-top: 2px;',
                    width: '100%',
                    labelWidth: 150,
					collapsible: true,
                    reader: new Ext.data.XmlReader({
                        record: 'item'
                    }, [{
                        name: 'id',
                        mapping: 'id'
                    },{
                        name: 'name',
                        mapping: 'name'
                    }, {
                        name: 'finishedTime',
                        mapping: 'finishedTime'
                    }, {
                        name: 'alarmTime',
                        mapping: 'alarmTime'
                    },{
                        name: 'isEffective',
                        mapping: 'isEffective'
                    },{
                        name: 'isFinished',
                        mapping: 'isFinished'
                    },{
                        name: 'comment',
                        mapping: 'comment'
                    }]),
                    items: [{
                        id: 'id',
                        name: 'id',
                        xtype: 'hidden'
                    }, {
                        id: 'piId',
                        name: 'piId',
                        xtype: 'hidden',
						value: idValue
                    },{
                                name: 'name',
                                id: 'name',
                                fieldLabel: tlMessage.get('ui.producttimeline.name'),
                                xtype: 'textfield',
                                anchor: '86%',
                                allowBlank: false,
                                blankText: message.get('message.edit.noblank'),
								maxLength: 64,
								maxLengthText: message.get('message.edit.toolong')
								
                     },{
                        layout: 'column',
                        items: [{
                            columnWidth: .5,
                            layout: 'form',
                            items: [{
                               name: 'finishedTime',
                                id: 'finishedTime',
                                fieldLabel: tlMessage.get('ui.producttimeline.finishedtime') + "(d/m/Y)",
                                xtype: 'datefield',
								//vtype: 'daterange',
								//startDateField: 'alarmTime',
                                anchor: '86%',
                                allowBlank: false,
                                blankText: message.get('message.edit.noblank')
                            }]
                        },{
                            columnWidth: .5,
                            layout: 'form',
                            items: [{
                               	name: 'alarmTime',
                                id: 'alarmTime',
                                fieldLabel: tlMessage.get('ui.producttimeline.alerttime') + "(d/m/Y)",
                                xtype: 'datefield',
								//vtype: 'daterange',
								//endDateField: 'finishedTime',
                                anchor: '86%',
                                allowBlank: false,
                                blankText: message.get('message.edit.noblank')
                            }]
                        }]
                    
                    },{
                        layout: 'column',
                        items: [{
                            columnWidth: .5,
                            layout: 'form',
                            items: [isEffectiveCombo]
                        },{
                            columnWidth: .5,
                            layout: 'form',
                            items: [isFinishedCombo]
                        }]
                    
                    },{
                            fieldLabel: tlMessage.get('ui.producttimeline.comment'),
                            name: 'comment',
                            xtype: 'textarea',
                            maxLength: 512,
                            width: '90%',
                            maxLengthText: message.get('message.edit.toolong')
                        }],
                    
                    buttons: [{
                        text: message.get('message.edit.save'),
                        handler: function(){
                            if (timeLineForm.getForm().isValid()) {
								document.getElementsByName('isEffective')[0].value = isEffectiveCombo.getValue();
                                document.getElementsByName('isFinished')[0].value = isFinishedCombo.getValue();
                                timeLineForm.getForm().submit({
                                    method: 'post',
                                    success: function(form, action){
                                        timeLineStore.reload();
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                        timeLineForm.getForm().reset();
                                    },
                                    failure: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                    }
                                });
                            }
                        }
                    }, {
                        text: message.get('message.edit.reset'),
                        handler: function(){
                            timeLineForm.getForm().reset();
                        }
                    }, {
                        text: message.get('message.edit.cancel'),
                        handler: function(){
                            if (startPage != null) {
                                window.location = 'product_time_line_list.html?startPage=' + startPage;
                            }
                            else {
                                window.location = 'product_time_line_list.html';
                            }
                        }
                    }]
                });
                
                
                timeLineForm.render('piTimeLineForm');
				
				timeLineStore = new Ext.data.Store({
                    url: '../../servlet/ProductTimeLineServlet?action=5&id=' + idValue,
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, [ 
                    'index', 'id', 'state','name', 'alarmTime', 'finishedTime', 'isEffective', 'isFinished', 'comment']),
                    remoteSort: true
                }); 
				
				timeLineGrid = new Ext.grid.GridPanel({
                    title: tlMessage.get('ui.producttimeline.listtitle'),
                    store: timeLineStore,
					stripeRows: true,
                    height: 560,
                    columns: [{
                        header: message.get('message.list.id'),
                        dataIndex: 'index'
                    }, {
                        header: tlMessage.get('ui.producttimeline.state'),
                        dataIndex: 'state',
						renderer: renderState
                    },{
                        header: tlMessage.get('ui.producttimeline.name'),
                        dataIndex: 'name'
                    }, {
                        header: tlMessage.get('ui.producttimeline.finishedtime') + "(d/m/Y)",
                        dataIndex: 'finishedTime'
                    }, {
                        header: tlMessage.get('ui.producttimeline.alerttime') + "(d/m/Y)",
                        dataIndex: 'alarmTime'
                    }, {
                        header: tlMessage.get('ui.producttimeline.iseffective'),
                        dataIndex: 'isEffective',
						renderer: renderIsEffective
                    },{
                        header: tlMessage.get('ui.producttimeline.isfinished'),
                        dataIndex: 'isFinished',
						renderer: renderIsFinished
                    },{
                        header: tlMessage.get('ui.producttimeline.comment'),
                        dataIndex: 'comment'
                    },{
                        header: message.get('message.list.eidt'),
						width: 50,
                        dataIndex: 'id',
                        renderer: renderEdit
                    },{
                        header: message.get('message.list.delete'),
                        width: 50,
                        dataIndex: 'id',
                        sortable: false,
                        renderer: renderDelete
                    }],
                    viewConfig: {
                        forceFit: true
                    },
                    loadMask: true,
                    renderTo: 'timeLineList'
                });
				
				timeLineStore.load();
				
            });
			
			function renderState(value, p, record, rowIndex){
				if(value == "1"){//STATE_INEFFECTIVE
					return String.format('<img ext:qtip="{0}" src="../../images/icons/flag_red.png" />', tlMessage.get('ui.producttimeline.state.ineffective'));
				}else if(value == "2"){// STATE_FINISHED
					return String.format('<img ext:qtip="{0}" src="../../images/icons/flag_green.png" />', tlMessage.get('ui.producttimeline.state.finished'));
				}else if(value == "5"){//STATE_ALARM
					return String.format('<img ext:qtip="{0}" src="../../images/icons/exclamation.png" />&nbsp;&nbsp;<img height="12" src="../../images/icons/e_mark.gif" />', tlMessage.get('ui.producttimeline.state.alarm'));					
				}else if(value == "3"){//STATE_ONGOING
					return String.format('<img ext:qtip="{0}" src="../../images/icons/flag_yellow.png" />', tlMessage.get('ui.producttimeline.state.ongoing'));
				}else if(value == "4"){//STATE_ABNORMAL
					return String.format('<img ext:qtip="{0}" src="../../images/icons/eye.png" />', tlMessage.get('ui.producttimeline.state.abnormal'));					
				}
			}
			
			function renderIsEffective(value, p, record){
				if(value == '01'){
					return String.format('<img ext:qtip="{0}" src="../../images/icons/tick.png" /></a>', message.get('message.list.yes'));		
				}else{
					return String.format('<img ext:qtip="{0}" src="../../images/icons/cross.png" /></a>', message.get('message.list.no'));				
				}
                    
            }
			
			function renderIsFinished(value, p, record){
                    if(value == '01'){
					return String.format('<img ext:qtip="{0}" src="../../images/icons/tick.png" /></a>', message.get('message.list.yes'));		
				}else{
					return String.format('<img ext:qtip="{0}" src="../../images/icons/cross.png" /></a>', message.get('message.list.no'));				
				}
            }
			
			function renderEdit(value, p, record){
                    return String.format('<a href="javascript: editItem(editCallback, {0});"><img src="../../images/icons/pencil.png" title="Edition" /></a>', record.id);
            }
                
            function renderDelete(value, p, record){
                return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="Supprimer"/></a>', record.id);
            }
			
			
			var editCallback = function(){
				Ext.getCmp('alarmTime').reset();
				Ext.getCmp('finishedTime').reset();
				timeLineForm.getForm().load({
					url:'../../servlet/ProductTimeLineServlet?action=3&id=' + editId, 
					waitMsg:Ext.LoadMask.prototype.msg, 
					success: function(form, action){
					}
				});
			}
			
			var deleteCallback = function(btn){
                if (btn == 'yes') {
                    Ext.Ajax.request({
                        url: '../../servlet/ProductTimeLineServlet?action=2&id=' + deleteId,
                        success: function(o){
                            if (o.responseText == 'success') {
                                timeLineStore.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
                }
            }
			
        </script>
    </head>
    <body>
        <div id="productIdentification">
        </div>
        <div id="piTimeLineForm">
        </div>
        <div id="timeLineList">
        </div>
    </body>
</html>
